import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
// 业务路由
export const routes = [
  {
    path: '/',
    name: 'Home',
    component: r => {
      require.ensure([], () => r(require('@/views/home/index')), 'home')
    },
    meta: { title: '首页', icon: '', auth: false }
  },
  {
    path: '/interface',
    name: 'Interface',
    component: r => {
      require.ensure([], () => r(require('@/views/interface/index')), 'interface')
    },
    meta: { title: '接口', icon: '', auth: false }
  },
  {
    path: '/search',
    name: 'Search',
    component: r => {
      require.ensure([], () => r(require('@/views/components/Empty')), 'search')
    },
    meta: { title: '查询', icon: '', auth: false },
    children: [
      {
        path: 'tool',
        name: 'SearchTool',
        component: r => {
          require.ensure([], () => r(require('@/views/search/tool/index')), 'SearchTool')
        },
        meta: { title: '工具', icon: '' }
      },
      {
        path: 'batch',
        name: 'SearchBatch',
        component: () => import(/* webpackChunkName: "ClientList" */ '@/views/search/batch'),
        meta: { title: '批量查询', icon: '' }
      }
    ]
  },
  // {
  //   path: '/datasource',
  //   name: 'Datasource',
  //   component: r => {
  //     require.ensure([], () => r(require('@/views/datasource/index')), 'datasource')
  //   },
  //   meta: { title: '数据源', icon: '', auth: false }
  // },
  {
    path: '/micro-search-sys',
    name: 'MicroSearchSys',
    component: r => {
      require.ensure([], () => r(require('@/views/micro-search-sys/index')), 'micro-search-sys')
    },
    meta: { title: '微查系统', icon: '', auth: false }
  },
  {
    path: '/custom-compose',
    name: 'CustomCompose',
    component: r => {
      require.ensure([], () => r(require('@/views/custom-compose/index')), 'custom-compose')
    },
    meta: { title: '随心搭', icon: '', auth: false }
  },
  // {
  //   path: '/member',
  //   name: 'Member',
  //   component: r => {
  //     require.ensure([], () => r(require('@/views/member/index')), 'member')
  //   },
  //   meta: { title: '会员', icon: '', auth: false }
  // },
  // 账号密码登录
  {
    path: '/login-account',
    name: 'LoginForAccount',
    // component: () => import(/* webpackChunkName: "login" */ '@/views/login/index'),
    component: r => {
      require.ensure([], () => r(require('@/views/login/index')), 'login')
    },
    hidden: true
  },
  // 验证码登录
  {
    path: '/login-code',
    name: 'LoginForCode',
    // component: () => import(/* webpackChunkName: "login" */ '@/views/login/index'),
    component: r => {
      require.ensure([], () => r(require('@/views/login/index')), 'login')
    },
    hidden: true
  },
  // 微信扫码登录
  {
    path: '/login-qr',
    name: 'LoginForQr',
    // component: () => import(/* webpackChunkName: "login" */ '@/views/login/index'),
    component: r => {
      require.ensure([], () => r(require('@/views/login/index')), 'login')
    },
    hidden: true
  },
  // {
  //   path: '/reset-pwd',
  //   name: 'ResetPwd',
  //   component: () => import(/* webpackChunkName: "ResetPwd" */ '@/views/login/ResetPwd'),
  //   hidden: true
  // },
  // {
  //   path: '/reset-success',
  //   name: 'ResetSuccess',
  //   component: () => import(/* webpackChunkName: "resetSuccess" */ '@/views/login/ResetSuccess'),
  //   hidden: true
  // },
  // {
  //   path: '/reset-fail',
  //   name: 'ResetFail',
  //   component: () => import(/* webpackChunkName: "resetFail" */ '@/views/login/ResetFail'),
  //   hidden: true
  // },

  {
    path: '/404',
    component: () => import(/* webpackChunkName: "404" */ '@/views/404'),
    hidden: true
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
